//配置所有路由的数组
import {RouteRecordRaw} from 'vue-router'

const routes: RouteRecordRaw[] = [
    {
        path: '/home',
        name: 'home',
        component: () => import('@/views/Home/Home.vue'),
        //路由元信息  是否显示Footer组件
        meta: {isShow: true}
    },
    {
        path: '/search/:keyword?', //:params  ?可选参数
        name: 'search',
        component: () => import('@/views/Search/Search.vue'),
        meta: {isShow: true}
    },
    {
        path: '/detail/:skuid',
        name: 'detail',
        component: () => import('@/views/Detail/Detail.vue'),
        meta: {isShow: true}
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/Login.vue'),
        meta: {isShow: false}
    },
    {
        path: '/register',
        name: 'register',
        component: () => import('@/views/Register.vue'),
        meta: {isShow: false}
    },
    {
        path: '/addcartsuccess',
        name: 'addcartsuccess',
        component: () => import('@/views/AddCartSuccess.vue'),
        meta: {isShow: true}
    },
    {
        path: '/shopcart',
        name: 'shopcart',
        component: () => import('@/views/ShopCart.vue'),
        meta: {isShow: true}
    },
    {
        path: '/trade',
        name: 'trade',
        component: () => import('@/views/Trade.vue'),
        meta: {isShow: true},
        //路由前置守卫
        beforeEnter: (to, from) => {
            //只能从购物车界面, 才能跳转到交易界面
            return from.path == '/shopcart'
        }
    },
    {
        path: '/pay',
        name: 'pay',
        component: () => import('@/views/Pay.vue'),
        meta: {isShow: true},
        beforeEnter: (to, from) => {
            //只能从交易界面, 才能跳转到支付界面
            return from.path == '/trade'
        }
    },
    {
        path: '/paysuccess',
        name: 'paysuccess',
        component: () => import('@/views/PaySuccess.vue'),
        meta: {isShow: true},
        beforeEnter: (to, from) => {
            //只能从支付界面, 才能跳转到支付成功界面
            return from.path == '/pay'
        }
    },
    {
        path: '/center',
        name: 'center',
        component: () => import('@/views/Center/Center.vue'),
        meta: {isShow: true},
        children: [
            {
                path: 'myorder',
                name: 'myorder',
                component: () => import('@/views/Center/MyOrder.vue')
            },
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ]
    },
    {
        path: '/',
        redirect: '/home'
    }
]

export default routes
